/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dhF9;

import android.app.Activity;
import android.os.Bundle;


public class dhF9Jni extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        //TextView  tv = new TextView(this);          
      //  tv.setText( "sumJNI="+ sum );
        int b;
        int snnr[] = {0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00};
        int ikey[] = {0x11,0x11,0x11};    //�û�ϵͳkey    
        int retKey[]={0,0,0,0,0,0,0,0,0};//��Ƭʵ������
        retKey=getKeyJNI(ikey,snnr); 
        int i =0;
        while (i<6)
        {	b=retKey[i];
        	i++;
        }
        int indata[] = {0x12,0x34,0x56,0x78,0x90,0x12,0x00,0x00};    //  
        
        retKey =mydes1encJNI(indata,snnr);
       i=0;
        while (i<8)
        {	b=retKey[i];
        	i++;
        }
        //C33555A7FC6AB485
        int intDeskey[] = {0xC3,0x35,0x55,0xA7,0xFC,0x6A,0xB4,0x85};   
        int  rand[] = {0x12,0x34,0x56,0x78,0x00,0x00,0x00,0x00};   
        retKey =getCardKeyJNIdes(intDeskey,rand,snnr);
        i=0;
        while (i<8)
        {	b=retKey[i];
        	i++;
        }
       
    }
    public  static byte[] calculatePass(byte [] logicCardID){
        dhF9Jni obj=new dhF9Jni();
        byte [] password=new byte[]{(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff};

        int a=1;
        int b = 2;
        int sum = obj. sumJNI(a,b);
        //  tv.setText( "sumJNI="+ sum );
        int snnr[]={0x8b,0x25,0xc3,0x28};//685293915,0x28D8C15B

        for (int i=0;i<logicCardID.length;i++){
            Byte temp=logicCardID[i];
            //    GlobalFunction.printText("tag",String.valueOf(temp.intValue()));

            snnr[i]=temp.intValue();

        }
        //  GlobalFunction.printText("tag","snr");

        int ikey[] =  {0x78,0x90,0x12};//用户系统key

        int retb[]={0,0,0,0,0,0,};
        retb=obj.getKeyJNI(ikey,snnr);
        int i =0;
        while (i<6)
        {	a=retb[i];
            password[i]=(byte)a;

            //   GlobalFunction.printText("tag",String.valueOf(a));

            i++;
        }
        // GlobalFunction.printText("tag","pass");
        return password;

    }


    public native int sumJNI(int i, int j) ;

    public native int[]  getKeyJNI(int[] ikey,int[] snr);
    public native int[]  mydes1encJNI(int[] indata,int[] snr);
    public native int[]  getCardKeyJNIdes( int[] ikey,int[] rand,int[] snr);
            
    
  //  public native String  unimplementedStringFromJNI();


   
    static {
        System.loadLibrary("DHJni");
    }
}
